﻿using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PlaxoSyncWM;

namespace TestPlaxoSyncWM {
    [TestClass]
    public class TestCertPolicy {
        private TestContext testContextInstance;
        private string username;
        private string password;
        private string GUID;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext {
            get { return testContextInstance; }
            set { testContextInstance = value; }
        }

        #region Additional test attributes

        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //

        #endregion

        [TestInitialize]
        public void InitializeMe() {
            username = "kiran.bellubbi@gmail.com";
            password = "campion";
            GUID = "PLXI:01000000000007076717590943671926";
        }

        [TestMethod]
        public void testCheckValidationResult() {
            ServicePointManager.CertificatePolicy = new CertPolicy();
            bool status;
            HttpWebRequest req;
            HttpWebResponse resp;
            string url =
                string.Format(
                    @"https://testapi.plaxo.com/rest?package=['Header', 'ProtoVer', '1', 'ClientID', {0}, 'Identifier',{1},'AuthMethod', 'Plaxo', 'Password',{2}, 'Client', 'Dev Clientname/1.0', 'OS', 'windows/service pack infinity', 'Platform', 'Outlook/2005']%0a['/Header']",
                    GUID, username, password);
            req = (HttpWebRequest) HttpWebRequest.Create(url);
            resp = (HttpWebResponse) req.GetResponse();
            if (resp.StatusCode == HttpStatusCode.OK)
                status = true;
            else status = false;
            Assert.IsTrue(status);
        }
    }
}